home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #12 / Amiga Plus CD - 2002 - No. 12.iso / AmigaOS / Aplus_Dev / AP-Website / download / pgp / pgp5gui-174b.lha / PGP5GUI-Src.lha / PGP5GUI-Src / PGPKInterface.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-23  |  13.2 KB  |  661 lines

  1. /*
  2. ** PGP5GUI - A GUI using Magic User Interface v3.8
  3. **
  4. ** Copyright 23-JUNE-1998 by Stefan Zakarias, All Rights Reserved.
  5. **
  6. ** This source code is released as FREEWARE - Use it for whatever you like,
  7. ** as long as NO financial reward is gained by you for such usage.
  8. **
  9. ** If you use any parts of the this source code for anything, give ME credit
  10. ** wherever credit is due, please ;-)
  11. */
  12.  
  13. /*
  14. ** Functions to handle the interface between PGPK and the GUI
  15. */
  16.  
  17. /* Library stuff */
  18. #include <libraries/mui.h>
  19. #include <dos/dostags.h>
  20.  
  21. /* Prototypes */
  22. #ifdef __GNUC__
  23. #include <clib/muimaster_protos.h>
  24. #include <proto/alib.h>
  25. #endif
  26.  
  27. #include <proto/muimaster.h>
  28. #include <proto/exec.h>
  29. #include <clib/alib_protos.h>
  30. #include <clib/alib_stdio_protos.h>
  31. #include <proto/dos.h>
  32.  
  33. /*  Ansi  */
  34. #include <string.h>
  35.  
  36. /* Include generated by GenCodeC */
  37. #include "PGP5GUI.h"
  38.  
  39. BOOL listget = FALSE;
  40.  
  41. char *caution_str = "CAUTION!";
  42. char *permanent_str = "The result of this function is PERMANENT...\nAre you sure you want to continue?";
  43. char *yesno_str = "Yes|No";
  44.  
  45. extern char *tempfile;
  46. extern char *pgp5_tmp_asc;
  47.  
  48. extern char *keys_extractpath;
  49. extern char *keys_extractfile;
  50.  
  51. extern char *exec_buff;
  52. extern char *keyidsbuff;
  53.  
  54. extern char *OK_str;
  55. extern char *ReadyMSG;
  56.  
  57. extern char *keyselection[];
  58. extern ULONG frtags[];
  59.  
  60. extern int GenerateKeyStrings(char *filename);
  61. extern int SelectPGPKey(struct ObjApp *app, char *sel[], char *title, ULONG multiselect);
  62. extern BOOL GetSaveASLFileName(struct ObjApp *app, char *hail, char *pathbuff, char *filebuff, char *tofile);
  63.  
  64. extern void PGP5_Execute(UBYTE *command, struct ObjApp *app);
  65. extern LONG GetCycle(Object *obj);
  66.  
  67. extern BOOL ReadClipToFile(char *tmp, struct ObjApp *app);
  68.  
  69. void
  70. PGPK_list(struct ObjApp *App)
  71. {
  72.     listget = TRUE;
  73.  
  74.     /* Get public-key list using "PGPK -l >T:pgp5keys" */
  75.     sprintf(exec_buff, "PGPK -l >%s", tempfile);
  76.     PGP5_Execute(exec_buff, App);
  77.  
  78.     listget = FALSE;
  79.  
  80.     /* Get key info strings into keystable[] */
  81.     if (GenerateKeyStrings(tempfile))
  82.     {
  83.         /* Probably failed if PGP5_Execute failed */
  84.         MUI_Request(App->App, App->WI_Main, 0, "FATAL ERROR...", OK_str,
  85.                     "Couldn't access '%s'", tempfile);
  86.     }
  87.  
  88.     /* Wake up the parent window */
  89.     set(App->WI_Main,MUIA_Window_Sleep,FALSE);
  90.  
  91.     /* Activate the parent window */
  92.     set(App->WI_Main,MUIA_Window_Activate,TRUE);
  93.  
  94.     set(App->TX_Status, MUIA_Text_Contents, ReadyMSG);
  95. }
  96.  
  97.  
  98. /*
  99. ** -a [keyfile keyfiles...]
  100. ** Adds the contents of 'keyfile(s)' to your keyring.
  101. */
  102. void
  103. Do_ADD_KEYADD(struct ObjApp *App)
  104. {
  105.     char *addkeybuff = "\0";
  106.     LONG clipmode;
  107.  
  108.     clipmode = GetCycle(App->CY_KeysAdd_CLIP);
  109.  
  110.     if (clipmode)
  111.     {
  112.         if (ReadClipToFile(pgp5_tmp_asc, App))
  113.         {
  114.             addkeybuff = pgp5_tmp_asc;
  115.         }
  116.     }
  117.     else
  118.     {
  119.         get(App->STR_PA_Keys_ADD_KEYFILE,MUIA_String_Contents,&addkeybuff);
  120.     }
  121.  
  122.     if (*addkeybuff)
  123.     {
  124.         /* Build up the command line to send to DOS */
  125.         sprintf(exec_buff, "PGPK -a \"%s\"", addkeybuff);
  126.  
  127.         /* Send the command to DOS */
  128.         PGP5_Execute(exec_buff, App);
  129.  
  130.         if (clipmode)
  131.         {
  132.             /* Clipboard mode...  Delete the temporary file (T:pgp5.tmp.asc) */
  133.             DeleteFile(pgp5_tmp_asc);
  134.         }
  135.  
  136.         /* Reload (edited) new list */
  137.         PGPK_list(App);
  138.     }
  139. }
  140.  
  141.  
  142. /*
  143. ** -c [userid]
  144. ** Checks the signatures of all keys on your public keyring.
  145. ** If [userid] is specified, only the signatures on that key
  146. ** are checked.
  147. ** Note that PGPK only allows for 1 selected userID!
  148. */
  149. BOOL
  150. Do_EDIT_KEYCHECK(struct ObjApp *App)
  151. {
  152.     int err;
  153.  
  154.     err = SelectPGPKey(App, keyselection, "Check Key(s)...",
  155.                         MUIV_Listview_MultiSelect_None);
  156.  
  157.     if (!err)
  158.     {
  159.         /* Build up the command line to send to DOS */
  160.         strcpy(exec_buff, "PGPK -c ");
  161.  
  162.         /* Check for a selected userID.    */
  163.         if (*keyselection[0])
  164.             strcat(exec_buff, keyselection[0]);
  165.  
  166.         /* Send the command to DOS */
  167.         PGP5_Execute(exec_buff, App);
  168.     }
  169.     else
  170.     {
  171.         if (err != -1)
  172.             return(FALSE);    /* Couldn't get MUI App opened */
  173.     }
  174.  
  175.     return(TRUE);
  176. }
  177.  
  178.  
  179. /*
  180. ** -d <userid>
  181. ** Toggles  the  disablement of <userid>'s key on your public keyring.
  182. ** Note that PGPK only allows for 1 selected userID!
  183. */
  184. BOOL
  185. Do_EDIT_KEYDISABLE(struct ObjApp *App)
  186. {
  187.     int err;
  188.  
  189.     err = SelectPGPKey(App, keyselection, "(En/Dis)able A Key...",
  190.                         MUIV_Listview_MultiSelect_None);
  191.  
  192.     if (!err)
  193.     {
  194.         /*
  195.         ** Check for a selected userID.
  196.         ** If nothing was selected, then skip this.
  197.         */
  198.         if (*keyselection[0])
  199.         {
  200.             /* Build up the command line to send to DOS */
  201.             sprintf(exec_buff, "PGPK -d %s", keyselection[0]);
  202.  
  203.             /* Send the command to DOS */
  204.             PGP5_Execute(exec_buff, App);
  205.  
  206.             /* Reload (edited) new list */
  207.             PGPK_list(App);
  208.         }
  209.     }
  210.     else
  211.     {
  212.         if (err != -1)
  213.             return(FALSE);    /* Couldn't get MUI App opened */
  214.     }
  215.  
  216.     return(TRUE);
  217. }
  218.  
  219.  
  220. /*
  221. ** -e <userid>
  222. ** Edits <userid>'s key.  If this is your key, it allows you to
  223. ** edit your userid(s) and passphrase.  If it is someone else's
  224. ** key, it allows you to edit the trust you have in that person
  225. ** as an introducer.
  226. ** Note that PGPK only allows for 1 selected userID!
  227. */
  228. BOOL
  229. Do_EDIT_KEYEDIT(struct ObjApp *App)
  230. {
  231.     int err;
  232.  
  233.     err = SelectPGPKey(App, keyselection, "Edit A Key...",
  234.                         MUIV_Listview_MultiSelect_None);
  235.  
  236.     if (!err)
  237.     {
  238.         /*
  239.         ** Check for a selected userID.
  240.         ** If nothing was selected, then skip this.
  241.         */
  242.         if (*keyselection[0])
  243.         {
  244.             /* Build up the command line to send to DOS */
  245.             sprintf(exec_buff, "PGPK -e %s", keyselection[0]);
  246.  
  247.             /* Send the command to DOS */
  248.             PGP5_Execute(exec_buff, App);
  249.  
  250.             /* Reload (edited) new list */
  251.             PGPK_list(App);
  252.         }
  253.     }
  254.     else
  255.     {
  256.         if (err != -1)
  257.             return(FALSE);    /* Couldn't get MUI App opened */
  258.     }
  259.  
  260.     return(TRUE);
  261. }
  262.  
  263.  
  264. /*
  265. ** -r <userid>
  266. ** Removes <userid>'s key from your public and private keyring (if it's there)
  267. ** Note that PGPK only allows for 1 selected userID!
  268. */
  269. BOOL
  270. Do_EDIT_KEYREMOVE(struct ObjApp *App)
  271. {
  272.     int err;
  273.  
  274.     err = SelectPGPKey(App, keyselection, "Remove A Key...",
  275.                         MUIV_Listview_MultiSelect_None);
  276.  
  277.     if (!err)
  278.     {
  279.         /*
  280.         ** Check for a selected userID.
  281.         ** If nothing was selected, then skip this.
  282.         */
  283.         if (*keyselection[0])
  284.         {
  285.             /* Build up the command line to send to DOS */
  286.             sprintf(exec_buff, "PGPK -r %s", keyselection[0]);
  287.  
  288.             /* Send the command to DOS */
  289.             PGP5_Execute(exec_buff, App);
  290.  
  291.             /* Reload (edited) new list */
  292.             PGPK_list(App);
  293.         }
  294.     }
  295.     else
  296.     {
  297.         if (err != -1)
  298.             return(FALSE);    /* Couldn't get MUI App opened */
  299.     }
  300.  
  301.     return(TRUE);
  302. }
  303.  
  304.  
  305. /*
  306. ** -rs <userid>
  307. ** Removes the given signature from your public keyring.
  308. ** Note that PGPK only allows for 1 selected userID!
  309. */
  310. BOOL
  311. Do_EDIT_KEYREMSIG(struct ObjApp *App)
  312. {
  313.     int err;
  314.  
  315.     err = SelectPGPKey(App, keyselection, "Remove A Signature...",
  316.                         MUIV_Listview_MultiSelect_None);
  317.  
  318.     if (!err)
  319.     {
  320.         /*
  321.         ** Check for a selected userID.
  322.         ** If nothing was selected, then skip this.
  323.         */
  324.         if (*keyselection[0])
  325.         {
  326.             /* Build up the command line to send to DOS */
  327.             sprintf(exec_buff, "PGPK -rs %s", keyselection[0]);
  328.  
  329.             /* Send the command to DOS */
  330.             PGP5_Execute(exec_buff, App);
  331.  
  332.             /* Reload (edited) new list */
  333.             PGPK_list(App);
  334.         }
  335.     }
  336.     else
  337.     {
  338.         if (err != -1)
  339.             return(FALSE);    /* Couldn't get MUI App opened */
  340.     }
  341.  
  342.     return(TRUE);
  343. }
  344.  
  345.  
  346. /*
  347. ** -ru <userid>
  348. ** Removes the given userid from your public and private keyrings.
  349. ** Note that PGPK only allows for 1 selected userID!
  350. */
  351. BOOL
  352. Do_EDIT_KEYREMUID(struct ObjApp *App)
  353. {
  354.     int err;
  355.  
  356.     err = SelectPGPKey(App, keyselection, "Remove A UserID...",
  357.                         MUIV_Listview_MultiSelect_None);
  358.  
  359.     if (!err)
  360.     {
  361.         /*
  362.         ** Check for a selected userID.
  363.         ** If nothing was selected, then skip this.
  364.         */
  365.         if (*keyselection[0])
  366.         {
  367.             /* Build up the command line to send to DOS */
  368.             sprintf(exec_buff, "PGPK -ru %s", keyselection[0]);
  369.  
  370.             /* Send the command to DOS */
  371.             PGP5_Execute(exec_buff, App);
  372.  
  373.             /* Reload (edited) new list */
  374.             PGPK_list(App);
  375.         }
  376.     }
  377.     else
  378.     {
  379.         if (err != -1)
  380.             return(FALSE);    /* Couldn't get MUI App opened */
  381.     }
  382.  
  383.     return(TRUE);
  384. }
  385.  
  386.  
  387. /*
  388. ** --revoke <userid>
  389. ** PERMANENTLY revokes the user selected key.
  390. ** Note that PGPK only allows for 1 selected userID!
  391. */
  392. BOOL
  393. Do_EDIT_KEYREVOKE(struct ObjApp *App)
  394. {
  395.     int err;
  396.  
  397.     /* Warn about irreversible function! */
  398.     if (MUI_Request(App->App, App->WI_Main, 0, caution_str, yesno_str, permanent_str))
  399.     {
  400.         err = SelectPGPKey(App, keyselection, "Permanently Revoke A Key...",
  401.                             MUIV_Listview_MultiSelect_None);
  402.  
  403.         if (!err)
  404.         {
  405.             /*
  406.             ** Check for a selected userID.
  407.             ** If nothing was selected, then skip this.
  408.             */
  409.             if (*keyselection[0])
  410.             {
  411.                 /* Build up the command line to send to DOS */
  412.                 sprintf(exec_buff, "PGPK --revoke %s", keyselection[0]);
  413.  
  414.                 /* Send the command to DOS */
  415.                 PGP5_Execute(exec_buff, App);
  416.  
  417.                 /* Reload (edited) new list */
  418.                 PGPK_list(App);
  419.             }
  420.         }
  421.         else
  422.         {
  423.             /* If user didn't click Cancel... */
  424.             if (err != -1)
  425.                 return(FALSE);        /* Couldn't get MUI App opened! */
  426.         }
  427.     }
  428.  
  429.     return(TRUE);
  430. }
  431.  
  432.  
  433. /*
  434. ** --revokes <userid>
  435. ** Permanently revokes a signature (if any) on the user selected key.
  436. ** Note that PGPK only allows for 1 selected userID!
  437. */
  438. BOOL
  439. Do_EDIT_KEYREVOKESIG(struct ObjApp *App)
  440. {
  441.     int err;
  442.  
  443.     /* Warn about irreversible function! */
  444.     if (MUI_Request(App->App, App->WI_Main, 0, caution_str, yesno_str, permanent_str))
  445.     {
  446.         err = SelectPGPKey(App, keyselection,
  447.                             "Permanently Revoke Your Signature On A Key...",
  448.                         MUIV_Listview_MultiSelect_None);
  449.  
  450.         if (!err)
  451.         {
  452.             /*
  453.             ** Check for a selected userID.
  454.             ** If nothing was selected, then skip this.
  455.             */
  456.             if (*keyselection[0])
  457.             {
  458.                 /* Build up the command line to send to DOS */
  459.                 sprintf(exec_buff, "PGPK --revokes %s", keyselection[0]);
  460.  
  461.                 /* Send the command to DOS */
  462.                 PGP5_Execute(exec_buff, App);
  463.  
  464.                 /* Reload (edited) new list */
  465.                 PGPK_list(App);
  466.             }
  467.         }
  468.         else
  469.         {
  470.             /* If user didn't click Cancel... */
  471.             if (err != -1)
  472.                 return(FALSE);        /* Couldn't get MUI App opened! */
  473.         }
  474.     }
  475.  
  476.     return(TRUE);
  477. }
  478.  
  479.  
  480. /*
  481. ** -s <userid> [-u <yourid>]
  482. ** Signs <userid>'s key with your default signing key.
  483. ** If -u is specified, uses that key, instead.
  484. ** Note that PGPK only allows for 1 selected userID!
  485. */
  486. BOOL
  487. Do_EDIT_KEYSIGN(struct ObjApp *App, BOOL doID)
  488. {
  489.     int err;
  490.  
  491.     err = SelectPGPKey(App, keyselection, "Sign A Key...",
  492.                         MUIV_Listview_MultiSelect_None);
  493.  
  494.     if (!err)
  495.     {
  496.         /*
  497.         ** Check for a selected userID.
  498.         ** If nothing was selected, then skip this.
  499.         */
  500.         if (*keyselection[0])
  501.         {
  502.             /* Build up the command line to send to DOS */
  503.             sprintf(exec_buff, "PGPK -s %s", keyselection[0]);
  504.  
  505.             if (doID)
  506.             {
  507.                 err = SelectPGPKey(App, keyselection, "Signing Key To Use...",
  508.                                     MUIV_Listview_MultiSelect_None);
  509.  
  510.                 if (!err)
  511.                 {
  512.                     strcat(exec_buff, " -u ");
  513.                     strcat(exec_buff, keyselection[0]);
  514.                 }
  515.             }
  516.  
  517.             /* If no error from doID's check... */
  518.             if (!err)
  519.             {
  520.                 /* Send the command to DOS */
  521.                 PGP5_Execute(exec_buff, App);
  522.  
  523.                 /* Reload (edited) new list */
  524.                 PGPK_list(App);
  525.             }
  526.         }
  527.     }
  528.     else
  529.     {
  530.         if (err != -1)
  531.             return(FALSE);    /* Couldn't get MUI App opened */
  532.     }
  533.  
  534.     return(TRUE);
  535. }
  536.  
  537.  
  538. /*
  539. ** -g
  540. ** Generate a public/private key pair.
  541. */
  542. void
  543. Do_MISC_KEYGEN(struct ObjApp *App)
  544. {
  545.     /* Build up the command line to send to DOS */
  546.     strcpy(exec_buff, "PGPK -g");
  547.  
  548.     /* Send the command to DOS */
  549.     PGP5_Execute(exec_buff, App);
  550.  
  551.     /* Reload (edited) new list */
  552.     PGPK_list(App);
  553. }
  554.  
  555.  
  556. /*
  557. ** -x <userids> +force -o <outfile>
  558. ** Extracts the specified userids keys in ASCII-armored form.
  559. */
  560. BOOL
  561. Do_MISC_KEYEXTRACT(struct ObjApp *App)
  562. {
  563.     int err, i;
  564.  
  565.     /* Title for the file requester */
  566.     char title[] = "Save Public Key(s) As...";
  567.     char tofile[512];
  568.  
  569.     err = SelectPGPKey(App, keyselection, "Extract Key(s)...",
  570.                         MUIV_Listview_MultiSelect_Default);
  571.  
  572.     if (!err)
  573.     {
  574.         /*
  575.         ** Check for a selected userID.
  576.         ** If nothing was selected, then skip this.
  577.         */
  578.         if (*keyselection[0])
  579.         {
  580.             strcpy(keyidsbuff, keyselection[0]);
  581.  
  582.             for (i = 1; i < 256; i++)
  583.             {
  584.                 if (*keyselection[i])
  585.                 {
  586.                     strcat(keyidsbuff, " ");
  587.                     strcat(keyidsbuff, keyselection[i]);
  588.                 }
  589.                 else
  590.                     break;
  591.             }
  592.  
  593.             /* Get name of file to save key to... */
  594.             if (GetSaveASLFileName(App, title, keys_extractpath, keys_extractfile, tofile))
  595.             {
  596.                 /* Build up the command line to send to DOS */
  597.                 sprintf(exec_buff, "PGPK -x %s +force -o \"%s\"", keyidsbuff, tofile);
  598.  
  599.                 /* Send the command to DOS and the output to 'tofile' */
  600.                 PGP5_Execute(exec_buff, App);
  601.             }
  602.         }
  603.     }
  604.     else
  605.     {
  606.         if (err != -1)
  607.             return(FALSE);    /* Couldn't get MUI App opened */
  608.     }
  609.  
  610.     return(TRUE);
  611. }
  612.  
  613.  
  614. /*
  615. ** -l[l] [userids]
  616. ** Lists information about a key.  '-ll'  lists  more information
  617. ** about a key.  If [userids] are specified, then those keys are listed.
  618. ** Otherwise, all keys are listed.
  619. */
  620. BOOL
  621. Do_MISC_KEYLIST(struct ObjApp *App)
  622. {
  623.     int err, i;
  624.  
  625.     err = SelectPGPKey(App, keyselection, "List Key(s)...",
  626.                         MUIV_Listview_MultiSelect_Default);
  627.  
  628.     if (!err)
  629.     {
  630.         /* If we have a selected userID we output verbose info about the key(s) */
  631.         if (*keyselection[0])
  632.         {
  633.             strcpy(keyidsbuff, keyselection[0]);
  634.  
  635.             for (i = 1; i < 256; i++)
  636.             {
  637.                 if (*keyselection[i])
  638.                 {
  639.                     strcat(keyidsbuff, " ");
  640.                     strcat(keyidsbuff, keyselection[i]);
  641.                 }
  642.                 else
  643.                     break;
  644.             }
  645.  
  646.             /* Build up the command line to send to DOS */
  647.             sprintf(exec_buff, "PGPK -ll %s", keyidsbuff);
  648.  
  649.             /* Send the command to DOS */
  650.             PGP5_Execute(exec_buff, App);
  651.         }
  652.     }
  653.     else
  654.     {
  655.         if (err != -1)
  656.             return(FALSE);    /* Couldn't get MUI App opened */
  657.     }
  658.  
  659.     return(TRUE);
  660. }
  661.